package edu.xjnu.uitls;

import lombok.Data;
import org.springframework.stereotype.Component;

@Component
@Data
public class Result {
    private Integer code; // 响应码
    private Object data; // 响应数据
    private String msg; // 响应的描述

    // 构造方法 Constructor
    public Result() {
    }

    public Result(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Result(Integer code, Object data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    // 成功响应
    public static Result success() {
        return new Result(200, "成功", "ok");
    }

    public static Result success(Integer code, Object data) {
        return new Result(code, data, "ok");
    }

    public static Result success(Object data) {
        return new Result(200, data, "ok");
    }

    public static Result success(Integer code, Object data, String msg) {
        return new Result(code, data, msg);
    }

    // 失败响应
    public static Result error() {
        return new Result(404, "出错了...", "error");
    }

    public static Result error(Integer code, Object data) {
        return new Result(code, data, "error");
    }

    public static Result error(Integer code, Object data, String msg) {
        return new Result(code, data, msg);
    }

}
